package main;

public class LeetCode11 {
    public int maxArea(int[] height) {  //超时版本
        int[][][] area = new int[height.length][height.length][2];
        for (int i = 0; i < height.length; i++) {  // 将数据展开为一个矩阵,矩阵元素为[index之差][两高度的较小值]
            for (int j = 0; j < i; j++) {
                area[i][j][0] = i - j;
                area[i][j][1] = height[i] < height[j] ? height[i] : height[j];
            }
        }
        int max = 0;
        for (int i = 0; i < height.length; i++) {  //遍历求最大值
            for (int j = 0; j < i; j++) {
                int tmp = area[i][j][0] * area[i][j][1];
                max = tmp > max ? tmp : max;
            }
        }
        return max;
    }
    int doublieptr(int[] height){  // 双指针解法,思路源于官方解答;
        int max =0;
        int low = 0;
        int high = height.length-1;
        while (low != high){
            int tmp = (high -low)*(height[low]<height[high]?height[low]:height[high]);
            max = tmp>max?tmp:max;
            if (height[low] < height[high]) {
                low++;
            } else {
                high--;
            }
        }

        return max;
    }

}
